package com.ppt.declaraciones;

import java.awt.Dimension;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

import com.ppt.constants.AppConstants;
import com.ppt.frame.MainFrame;

@Entity
public class DeclaracionDialog extends JDialog implements WindowListener{

	private static final long serialVersionUID = 1L;
	@ManyToOne
	private MainFrame frame;
	
	@ManyToOne
	private DeclaracionBase declaracion;
	
	private String referencia;
	
	protected DeclaracionDialog() {
	}

	public DeclaracionDialog(MainFrame frame, String referencia){
		super(frame);
		setMinimumSize(new Dimension(AppConstants.MINIMUM_SIZE_X, AppConstants.MINIMUM_SIZE_Y));
		this.frame = frame;
		this.referencia = referencia;
		
		setModal(true);
		setLocationRelativeTo(null);
		setTitle("ID: Orden de Tarabajo (REF: "+referencia+")");
		
		declaracion = new DeclaracionBase(referencia);
		getContentPane().add(declaracion);
		
		
		
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent e) {
		JOptionPane cerrarDialog = new JOptionPane();
		cerrarDialog.setVisible(true);
		int i = JOptionPane.showConfirmDialog(frame, "¿Seguro que quiere cerrar la declaración?", "Titulo", JOptionPane.YES_NO_OPTION);
		if (i == JOptionPane.YES_OPTION) {
			dispose();
		}
		if (i == JOptionPane.NO_OPTION) {
			cerrarDialog.setVisible(false);
		}
	}

	@Override
	public void windowClosing(WindowEvent e) {
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

}
